package cn.itcast.Rainbow_self_mention.Dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class SqlHelper extends SQLiteOpenHelper {


    public SqlHelper(@Nullable Context context) {
        super(context, "database.db", null, 2);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE logined(" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT , " +//id
                "username VARCHAR(20)," +                  // 用户姓名
                "userphone VARCHAR(20)," +                 // 用户电话号码
                "userid INTEGER)");                         // 用户id

        db.execSQL("CREATE TABLE HISTORY(" +
                "_id INTEGER PRIMARY KEY ," +               //订单位于本表的位置
                "NUMBER VARCHAR(40) UNIQUE ," +             //订单号
                "NAME_OF_SUBMIT VARCHAR(20) NOT NULL," +    //寄件人姓名
                "PHONE_OF_SUBMIT VARCHAR(20) NOT NULL," +   //寄件人手机
                "TIME_OF_ORDER DATETIME NOT NULL," +        //提交订单时间
                "TIME_OF_SUBMIT DATETIME DEFAULT NULL," +   //投放时间
                "NAME_OF_RECEIVER VARCHAR(20) NOT NULL," +  //收件人姓名
                "PHONE_OF_RECEIVER VARCHAR(20) NOT NULL," + //收件人电话
                "TIME_OF_RECEIVER DATETIME DEFAULT NULL," + //签收时间
                "LOCATION TEXT NOT NULL," +                 //柜子地址
                "NAME_OF_PRODUCTION VARCHAR(10) NOT NULL," +//物品名称
                "NAME_OF_PICTURE VARCHAR(30) NOT NULL," +   //照片名称
                "TEMPERATURE INTEGER ," +                   //当前温度
                "RECEIVE_OR_NOT INTEGER )");                //是否签收******1代表提交订单未投件*****
                                                            // **2代表投放外卖未取件********3代表取件完成


        db.execSQL("CREATE TABLE chose(" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT , " +//id
                "which INTEGER DEFAULT 0)");

        db.execSQL("CREATE TABLE box(" +
                "_id INTEGER PRIMARY KEY ," +
                "box_id INT UNIQUE, " +
                "location TEXT NOT NULL," +
                "longitude DOUBLE NOT NULL, "+
                "lantitude DOUBLE NOT NULL," +
                "distance DOUBLE NOT NULL)");

        db.execSQL("create unique index if not exists NUM on HISTORY(NUMBER)");
        db.execSQL("create unique index if not exists BNUM on box(box_id)");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
